package org.dppc.fine4j.proxychain;

import java.util.List;



/**
 * 方法代理（方法拦截器）链 
 * 
 * @author maomh
 *
 */
public class MethodProxyChain {
	// 游标
	private int index =0;
	private List<MethodProxy> methodProxies;
	
	public MethodProxyChain(List<MethodProxy> methodProxies) {
		this.methodProxies =methodProxies;
	}
	
	/**
	 * 继续执行方法代理链
	 * 
	 * @param command
	 * @return
	 * @throws Exception
	 */
	public Object doInvoke(MethodCommand command) throws Throwable {
		Object result =null;
		if (index < methodProxies.size()) {
			MethodProxy mp =methodProxies.get(index);
			++index;
			result =mp.doInvoke(command, this);
		} else {
			result =command.execute();
		}
		return result;
	}
}
